/*
 * Singularity Engine
 * Copyright (C) 2010 Vyacheslav Vorobyov, All rights reserved.
 * See LICENSE for full license information.
 */
package org.singularity.io.util;

import java.io.IOException;

import org.singularity.io.CloseablePipe;

/**
 * Transit pipe. That is a pipe that has a next subsequent pipe results to send to. 
 * @author vjache
 *
 */
public abstract class TPipe<T,T1> implements CloseablePipe<T> {

	protected CloseablePipe<T1> _next;

	/**
	 * 
	 */
	protected TPipe() {}
	/**
	 * 
	 * @param aNext
	 */
	protected TPipe(CloseablePipe<T1> aNext) 
	{setNext(aNext);}
	/**
	 * 
	 * @param aNext
	 */
	public void setNext(CloseablePipe<T1> aNext)
	{_next = aNext;}
	/**
	 * 
	 * @return
	 */
	protected final CloseablePipe<T1> getNext()
	{return _next;}
	
	@Override
	public void flush() throws IOException {
		if(_next!=null)
			_next.flush();
	}

	/* (non-Javadoc)
	 * @see java.io.Closeable#close()
	 */
	@Override
	public void close() throws IOException {
		flush();
		if(_next!=null)
			_next.close();
	}
}
